library(haven);library(xtable);library(vtable)
setwd("~/Dropbox/DiffuseSupportComparativePerspective/CtsDifferentPaper/Qualtrics")
d <- read_dta("CtsDifferent_Replication_RR.dta")
dems <- subset(d, pid<4)
reps <- subset(d, pid>4)

#######################
##Table A1
#######################
sumStats <- d
sumStats$proposalCondition <- factor(sumStats$proposalCondition)
sumStats$copartisanCondition <- factor(sumStats$copartisanCondition)
st(sumStats[ , ! names(sumStats) %in% c("pid")],summ=c('mean(x)',   'sd(x)', 'min(x)', 'pctile(x)[50]', 'max(x)'),out="latex")

#######################
##Figure 1
#######################
court_overall <- t.test(subset(d,proposalCondition==2)$summaryDV)
court_nonpartisan <- t.test(subset(d,proposalCondition==2 & copartisanCondition==0)$summaryDV)
court_copartisan <- t.test(subset(d,proposalCondition==2 & copartisanCondition==1)$summaryDV)
court_outpartisan <- t.test(subset(d,proposalCondition==2 & copartisanCondition==2)$summaryDV)
doe_overall <- t.test(subset(d,proposalCondition==1)$summaryDV)
doe_nonpartisan <- t.test(subset(d,proposalCondition==1 & copartisanCondition==0)$summaryDV)
doe_copartisan <- t.test(subset(d,proposalCondition==1 & copartisanCondition==1)$summaryDV)
doe_outpartisan <- t.test(subset(d,proposalCondition==1 & copartisanCondition==2)$summaryDV)
po_overall <- t.test(subset(d,proposalCondition==0)$summaryDV)
po_nonpartisan <- t.test(subset(d,proposalCondition==0 & copartisanCondition==0)$summaryDV)
po_copartisan <- t.test(subset(d,proposalCondition==0 & copartisanCondition==1)$summaryDV)
po_outpartisan <- t.test(subset(d,proposalCondition==0 & copartisanCondition==2)$summaryDV)
diff_overall <- t.test(subset(d,proposalCondition==2)$summaryDV,subset(d,proposalCondition==1)$summaryDV)
diff_nonpartisan <- t.test(subset(d,proposalCondition==2 & copartisanCondition==0)$summaryDV,subset(d,proposalCondition==1 & copartisanCondition==0)$summaryDV)
diff_copartisan <- t.test(subset(d,proposalCondition==2 & copartisanCondition==1)$summaryDV,subset(d,proposalCondition==1 & copartisanCondition==1)$summaryDV)
diff_outpartisan <- t.test(subset(d,proposalCondition==2 & copartisanCondition==2)$summaryDV,subset(d,proposalCondition==1 & copartisanCondition==2)$summaryDV)

ctpo_diff_overall <- t.test(subset(d,proposalCondition==2)$summaryDV,subset(d,proposalCondition==0)$summaryDV)
ctpo_diff_nonpartisan <- t.test(subset(d,proposalCondition==2 & copartisanCondition==0)$summaryDV,subset(d,proposalCondition==0 & copartisanCondition==0)$summaryDV)
ctpo_diff_copartisan <- t.test(subset(d,proposalCondition==2 & copartisanCondition==1)$summaryDV,subset(d,proposalCondition==0 & copartisanCondition==1)$summaryDV)
ctpo_diff_outpartisan <- t.test(subset(d,proposalCondition==2 & copartisanCondition==2)$summaryDV,subset(d,proposalCondition==0 & copartisanCondition==2)$summaryDV)

doepo_diff_overall <- t.test(subset(d,proposalCondition==1)$summaryDV,subset(d,proposalCondition==0)$summaryDV)
doepo_diff_nonpartisan <- t.test(subset(d,proposalCondition==1 & copartisanCondition==0)$summaryDV,subset(d,proposalCondition==0 & copartisanCondition==0)$summaryDV)
doepo_diff_copartisan <- t.test(subset(d,proposalCondition==1 & copartisanCondition==1)$summaryDV,subset(d,proposalCondition==0 & copartisanCondition==1)$summaryDV)
doepo_diff_outpartisan <- t.test(subset(d,proposalCondition==1 & copartisanCondition==2)$summaryDV,subset(d,proposalCondition==0 & copartisanCondition==2)$summaryDV)

pdf("summaryQualtricsMainRP.pdf",width=15,height=5,paper='special') 
par(mar=c(5.1,6, 4.1, 2.1),mfrow=c(1,3))
 plot(c(3,2,1),c(po_overall$estimate,doe_overall$estimate,court_overall$estimate),ylab="Incumbent Support",
      main="Direct Effects",cex.main=2,xaxt="n", xlab="", xlim=c(.75,3.25),
      cex.axis=1.5,cex.lab=1.5,ylim=c(.2,.6),pch=19,cex=2)
 mtext(at=c(1,2,3),text=c("Supreme\nCourt","Department\nof Education","Post\nOffice"),side=1,line=3,cex=1)
 segments(x0=3,x1=3,y0=po_overall$conf.int[1],y1=po_overall$conf.int[2],lwd=3, col="black")
 segments(x0=2,x1=2,y0=doe_overall$conf.int[1],y1=doe_overall$conf.int[2],lwd=3, col="black")
 segments(x0=1,x1=1,y0=court_overall$conf.int[1],y1=court_overall$conf.int[2],lwd=3, col="black")
 
plot(c(.9,1,1.1),c(court_nonpartisan$estimate,court_copartisan$estimate,court_outpartisan$estimate),ylab="Incumbent Support",col=c("#0072ce","#1e407c","darkgray"),
     main="Direct Effects",cex.main=2,xaxt="n", xlab="", xlim=c(.75,3.25),
     cex.axis=1.5,cex.lab=1.5,ylim=c(.2,.6),pch=c(19,15,17),cex=2)
mtext(at=c(1,2,3),text=c("Supreme\nCourt","Department\nof Education","Post\nOffice"),side=1,line=3,cex=1)
points(x=c(1.9,2,2.1),y=c(doe_nonpartisan$estimate,doe_copartisan$estimate,doe_outpartisan$estimate),pch=c(19,15,17),col=c("#0072ce","#1e407c","darkgray"),cex=2)
segments(x0=.9,x1=.9,y0=court_nonpartisan$conf.int[1],y1=court_nonpartisan$conf.int[2],lwd=3, col="#0072ce")
segments(x0=1,x1=1,y0=court_copartisan$conf.int[1],y1=court_copartisan$conf.int[2],lwd=3, col="#1e407c")
segments(x0=1.1,x1=1.1,y0=court_outpartisan$conf.int[1],y1=court_outpartisan$conf.int[2],lwd=3, col="darkgray")
segments(x0=1.9,x1=1.9,y0=doe_nonpartisan$conf.int[1],y1=doe_nonpartisan$conf.int[2],lwd=3, col="#0072ce")
segments(x0=2,x1=2,y0=doe_copartisan$conf.int[1],y1=doe_copartisan$conf.int[2],lwd=3, col="#1e407c")
segments(x0=2.1,x1=2.1,y0=doe_outpartisan$conf.int[1],y1=doe_outpartisan$conf.int[2],lwd=3, col="darkgray")
points(x=c(2.9,3,3.1),y=c(po_nonpartisan$estimate,po_copartisan$estimate,po_outpartisan$estimate),pch=c(19,15,17),col=c("#0072ce","#1e407c","darkgray"),cex=2)
segments(x0=2.9,x1=2.9,y0=po_nonpartisan$conf.int[1],y1=po_nonpartisan$conf.int[2],lwd=3, col="#0072ce")
segments(x0=3,x1=3,y0=po_copartisan$conf.int[1],y1=po_copartisan$conf.int[2],lwd=3, col="#1e407c")
segments(x0=3.1,x1=3.1,y0=po_outpartisan$conf.int[1],y1=po_outpartisan$conf.int[2],lwd=3, col="darkgray")

legend("bottomright",pch=c(19,15,17),c("No Party","Copartisan","Outpartisan"),col=c("#0072ce","#1e407c","darkgray"),cex=1.5)

plot(c(1,2,3,4),c(diff_overall$estimate[1]-diff_overall$estimate[2],
                  diff_nonpartisan$estimate[1]-diff_nonpartisan$estimate[2],
                  diff_copartisan$estimate[1]-diff_copartisan$estimate[2],
                  diff_outpartisan$estimate[1]-diff_outpartisan$estimate[2]),ylab="mean(Court) - mean(Dept. of Ed.)", 
     col=c("black","#0072ce","#1e407c","darkgray"),
     main="Mean Differences",cex.main=2,xaxt="n", xlab="", xlim=c(.75,4.25),
     cex.axis=1.5,cex.lab=1.5,ylim=c(-.3,.1),pch=c(18,19,15,17),bg="black",cex=c(2.5,2,2,2))
mtext(at=c(1,2,3,4),text=c("Overall","No Party","Copartisan","Outpartisan"),side=1,line=1.5,cex=1)
segments(x0=1,x1=1,y0=diff_overall$conf.int[1],y1=diff_overall$conf.int[2],lwd=3, col="black")
segments(x0=2,x1=2,y0=diff_nonpartisan$conf.int[1],y1=diff_nonpartisan$conf.int[2],lwd=3, col="#0072ce")
segments(x0=3,x1=3,y0=diff_copartisan$conf.int[1],y1=diff_copartisan$conf.int[2],lwd=3, col="#1e407c")
segments(x0=4,x1=4,y0=diff_outpartisan$conf.int[1],y1=diff_outpartisan$conf.int[2],lwd=3, col="darkgray")
abline(h=0,col="gray70",lwd=3,lty=2)
dev.off()

#######################
##Figure A1
#######################
pdf("summaryQualtricsOtherTwoRP.pdf",width=10,height=5,paper='special') 
par(mar=c(5.1,6, 4.1, 2.1),mfrow=c(1,2))
plot(c(1,2,3,4),c(ctpo_diff_overall$estimate[1]-ctpo_diff_overall$estimate[2],
                  ctpo_diff_nonpartisan$estimate[1]-ctpo_diff_nonpartisan$estimate[2],
                  ctpo_diff_copartisan$estimate[1]-ctpo_diff_copartisan$estimate[2],
                  ctpo_diff_outpartisan$estimate[1]-ctpo_diff_outpartisan$estimate[2]),ylab="mean(Court) - mean(Post Office)", 
     col=c("black","#0072ce","#1e407c","darkgray"),
     main="Mean Differences",cex.main=2,xaxt="n", xlab="", xlim=c(.75,4.25),
     cex.axis=1,cex.lab=1.2,ylim=c(-.3,.1),pch=c(18,19,15,17),bg="black",cex=c(2.5,2,2,2))
mtext(at=c(1,2,3,4),text=c("Overall","No Party","Copartisan","Outpartisan"),side=1,line=1,cex=1)
segments(x0=1,x1=1,y0=ctpo_diff_overall$conf.int[1],y1=ctpo_diff_overall$conf.int[2],lwd=3, col="black")
segments(x0=2,x1=2,y0=ctpo_diff_nonpartisan$conf.int[1],y1=ctpo_diff_nonpartisan$conf.int[2],lwd=3, col="#0072ce")
segments(x0=3,x1=3,y0=ctpo_diff_copartisan$conf.int[1],y1=ctpo_diff_copartisan$conf.int[2],lwd=3, col="#1e407c")
segments(x0=4,x1=4,y0=ctpo_diff_outpartisan$conf.int[1],y1=ctpo_diff_outpartisan$conf.int[2],lwd=3, col="darkgray")
abline(h=0,col="gray70",lwd=3,lty=2)

plot(c(1,2,3,4),c(doepo_diff_overall$estimate[1]-doepo_diff_overall$estimate[2],
                  doepo_diff_nonpartisan$estimate[1]-doepo_diff_nonpartisan$estimate[2],
                  doepo_diff_copartisan$estimate[1]-doepo_diff_copartisan$estimate[2],
                  doepo_diff_outpartisan$estimate[1]-doepo_diff_outpartisan$estimate[2]),ylab="mean(Dept. of Ed.) - mean(Post Office)", 
     col=c("black","#0072ce","#1e407c","darkgray"),
     main="Mean Differences",cex.main=2,xaxt="n", xlab="", xlim=c(.75,4.25),
     cex.axis=1,cex.lab=1.2,ylim=c(-.3,.1),pch=c(18,19,15,17),bg="black",cex=c(3,2,2,2))
mtext(at=c(1,2,3,4),text=c("Overall","No Party","Copartisan","Outpartisan"),side=1,line=1,cex=1)
segments(x0=1,x1=1,y0=doepo_diff_overall$conf.int[1],y1=doepo_diff_overall$conf.int[2],lwd=3, col="black")
segments(x0=2,x1=2,y0=doepo_diff_nonpartisan$conf.int[1],y1=doepo_diff_nonpartisan$conf.int[2],lwd=3, col="#0072ce")
segments(x0=3,x1=3,y0=doepo_diff_copartisan$conf.int[1],y1=doepo_diff_copartisan$conf.int[2],lwd=3, col="#1e407c")
segments(x0=4,x1=4,y0=doepo_diff_outpartisan$conf.int[1],y1=doepo_diff_outpartisan$conf.int[2],lwd=3, col="darkgray")
abline(h=0,col="gray70",lwd=3,lty=2)
dev.off()


#######################
##Table A3
#######################
dvs <- c("summaryDV","voteDV","proposalDV","jobpDV","mobilDV")
m <- matrix(nrow=length(dvs),ncol=7)
colnames(m) <- c("Variable","Ct_DoE","Ct_DoE.P","Ct_PO","Ct_PO.P","DoE_PO","DoE_PO.P")
for (i in 1:length(dvs)){
  eval(parse(text=paste0("curb_vs_defend <- t.test(subset(d,proposalCondition==2)$",dvs[i],",subset(d,proposalCondition==1)$",dvs[i],")")))
  eval(parse(text=paste0("curb_vs_statement <- t.test(subset(d,proposalCondition==2)$",dvs[i],",subset(d,proposalCondition==0)$",dvs[i],")")))
  eval(parse(text=paste0("defend_vs_statement <- t.test(subset(d,proposalCondition==1)$",dvs[i],",subset(d,proposalCondition==0)$",dvs[i],")")))
  #curb_vs_defend <- t.test(subset(d,proposalCondition==2)$dvs[i],subset(d,proposalCondition==3)$dvs[i])
  #curb_vs_statement <- t.test(subset(d,proposalCondition==2)$dvs[i],subset(d,proposalCondition==1)$dvs[i])
  #defend_vs_statement <- t.test(subset(d,proposalCondition==3)$dvs[i],subset(d,proposalCondition==1)$dvs[i])
  m[i,1] <- dvs[i]
  m[i,2] <- unname(format(round((curb_vs_defend$estimate[1]-curb_vs_defend$estimate[2]),2), nsmall = 2))
  if (format(round(curb_vs_defend$p.value,2), nsmall = 2)=="0.00"){
    m[i,3] <- "< 0.01"
  } else {
    m[i,3] <- format(round(curb_vs_defend$p.value,2), nsmall = 2)
  }
  m[i,4] <- unname(format(round((curb_vs_statement$estimate[1]-curb_vs_statement$estimate[2]),2), nsmall = 2))
  if (format(round(curb_vs_statement$p.value,2), nsmall = 2)=="0.00"){
    m[i,5] <- "< 0.01"
  } else {
    m[i,5] <- format(round(curb_vs_statement$p.value,2), nsmall = 2)
  }
  m[i,6] <- unname(format(round((defend_vs_statement$estimate[1]-defend_vs_statement$estimate[2]),2), nsmall = 2))
  if (format(round(defend_vs_statement$p.value,2), nsmall = 2)=="0.00"){
    m[i,7] <- "< 0.01"
  } else {
    m[i,7] <- format(round(defend_vs_statement$p.value,2), nsmall = 2)
  }
}
m
print(xtable(m), include.rownames=FALSE)

##Nonpartisan
m <- matrix(nrow=length(dvs),ncol=7)
colnames(m) <- c("Variable","Ct_DoE","Ct_DoE.P","Ct_PO","Ct_PO.P","DoE_PO","DoE_PO.P")
for (i in 1:length(dvs)){
  eval(parse(text=paste0("curb_vs_defend <- t.test(subset(d,proposalCondition==2 & copartisanCondition==0)$",dvs[i],",subset(d,proposalCondition==1 & copartisanCondition==0)$",dvs[i],")")))
  eval(parse(text=paste0("curb_vs_statement <- t.test(subset(d,proposalCondition==2 & copartisanCondition==0)$",dvs[i],",subset(d,proposalCondition==0 & copartisanCondition==0)$",dvs[i],")")))
  eval(parse(text=paste0("defend_vs_statement <- t.test(subset(d,proposalCondition==1 & copartisanCondition==0)$",dvs[i],",subset(d,proposalCondition==0 & copartisanCondition==0)$",dvs[i],")")))
  m[i,1] <- dvs[i]
  m[i,2] <- unname(format(round((curb_vs_defend$estimate[1]-curb_vs_defend$estimate[2]),2), nsmall = 2))
  if (format(round(curb_vs_defend$p.value,2), nsmall = 2)=="0.00"){
    m[i,3] <- "< 0.01"
  } else {
    m[i,3] <- format(round(curb_vs_defend$p.value,2), nsmall = 2)
  }
  m[i,4] <- unname(format(round((curb_vs_statement$estimate[1]-curb_vs_statement$estimate[2]),2), nsmall = 2))
  if (format(round(curb_vs_statement$p.value,2), nsmall = 2)=="0.00"){
    m[i,5] <- "< 0.01"
  } else {
    m[i,5] <- format(round(curb_vs_statement$p.value,2), nsmall = 2)
  }
  m[i,6] <- unname(format(round((defend_vs_statement$estimate[1]-defend_vs_statement$estimate[2]),2), nsmall = 2))
  if (format(round(defend_vs_statement$p.value,2), nsmall = 2)=="0.00"){
    m[i,7] <- "< 0.01"
  } else {
    m[i,7] <- format(round(defend_vs_statement$p.value,2), nsmall = 2)
  }
}
m
print(xtable(m), include.rownames=FALSE)


##Copartisan
m <- matrix(nrow=length(dvs),ncol=7)
colnames(m) <- c("Variable","Ct_DoE","Ct_DoE.P","Ct_PO","Ct_PO.P","DoE_PO","DoE_PO.P")
for (i in 1:length(dvs)){
  eval(parse(text=paste0("curb_vs_defend <- t.test(subset(d,proposalCondition==2 & copartisanCondition==1)$",dvs[i],",subset(d,proposalCondition==1 & copartisanCondition==1)$",dvs[i],")")))
  eval(parse(text=paste0("curb_vs_statement <- t.test(subset(d,proposalCondition==2 & copartisanCondition==1)$",dvs[i],",subset(d,proposalCondition==0 & copartisanCondition==1)$",dvs[i],")")))
  eval(parse(text=paste0("defend_vs_statement <- t.test(subset(d,proposalCondition==1 & copartisanCondition==1)$",dvs[i],",subset(d,proposalCondition==0 & copartisanCondition==1)$",dvs[i],")")))
  m[i,1] <- dvs[i]
  m[i,2] <- unname(format(round((curb_vs_defend$estimate[1]-curb_vs_defend$estimate[2]),2), nsmall = 2))
  if (format(round(curb_vs_defend$p.value,2), nsmall = 2)=="0.00"){
    m[i,3] <- "< 0.01"
  } else {
    m[i,3] <- format(round(curb_vs_defend$p.value,2), nsmall = 2)
  }
  m[i,4] <- unname(format(round((curb_vs_statement$estimate[1]-curb_vs_statement$estimate[2]),2), nsmall = 2))
  if (format(round(curb_vs_statement$p.value,2), nsmall = 2)=="0.00"){
    m[i,5] <- "< 0.01"
  } else {
    m[i,5] <- format(round(curb_vs_statement$p.value,2), nsmall = 2)
  }
  m[i,6] <- unname(format(round((defend_vs_statement$estimate[1]-defend_vs_statement$estimate[2]),2), nsmall = 2))
  if (format(round(defend_vs_statement$p.value,2), nsmall = 2)=="0.00"){
    m[i,7] <- "< 0.01"
  } else {
    m[i,7] <- format(round(defend_vs_statement$p.value,2), nsmall = 2)
  }
}
m
print(xtable(m), include.rownames=FALSE)


##Outpartisan
m <- matrix(nrow=length(dvs),ncol=7)
colnames(m) <- c("Variable","Ct_DoE","Ct_DoE.P","Ct_PO","Ct_PO.P","DoE_PO","DoE_PO.P")
for (i in 1:length(dvs)){
  eval(parse(text=paste0("curb_vs_defend <- t.test(subset(d,proposalCondition==2 & copartisanCondition==2)$",dvs[i],",subset(d,proposalCondition==1 & copartisanCondition==2)$",dvs[i],")")))
  eval(parse(text=paste0("curb_vs_statement <- t.test(subset(d,proposalCondition==2 & copartisanCondition==2)$",dvs[i],",subset(d,proposalCondition==0 & copartisanCondition==2)$",dvs[i],")")))
  eval(parse(text=paste0("defend_vs_statement <- t.test(subset(d,proposalCondition==1 & copartisanCondition==2)$",dvs[i],",subset(d,proposalCondition==0 & copartisanCondition==2)$",dvs[i],")")))
  m[i,1] <- dvs[i]
  m[i,2] <- unname(format(round((curb_vs_defend$estimate[1]-curb_vs_defend$estimate[2]),2), nsmall = 2))
  if (format(round(curb_vs_defend$p.value,2), nsmall = 2)=="0.00"){
    m[i,3] <- "< 0.01"
  } else {
    m[i,3] <- format(round(curb_vs_defend$p.value,2), nsmall = 2)
  }
  m[i,4] <- unname(format(round((curb_vs_statement$estimate[1]-curb_vs_statement$estimate[2]),2), nsmall = 2))
  if (format(round(curb_vs_statement$p.value,2), nsmall = 2)=="0.00"){
    m[i,5] <- "< 0.01"
  } else {
    m[i,5] <- format(round(curb_vs_statement$p.value,2), nsmall = 2)
  }
  m[i,6] <- unname(format(round((defend_vs_statement$estimate[1]-defend_vs_statement$estimate[2]),2), nsmall = 2))
  if (format(round(defend_vs_statement$p.value,2), nsmall = 2)=="0.00"){
    m[i,7] <- "< 0.01"
  } else {
    m[i,7] <- format(round(defend_vs_statement$p.value,2), nsmall = 2)
  }
}
m
print(xtable(m), include.rownames=FALSE)

#######################
##Figure A2
#######################
##Summary PLOT
court_overall <- t.test(subset(d,proposalCondition==2)$summaryDV)
court_nonpartisan <- t.test(subset(d,proposalCondition==2 & copartisanCondition==0)$summaryDV)
court_copartisan <- t.test(subset(d,proposalCondition==2 & copartisanCondition==1)$summaryDV)
court_outpartisan <- t.test(subset(d,proposalCondition==2 & copartisanCondition==2)$summaryDV)
doe_overall <- t.test(subset(d,proposalCondition==1)$summaryDV)
doe_nonpartisan <- t.test(subset(d,proposalCondition==1 & copartisanCondition==0)$summaryDV)
doe_copartisan <- t.test(subset(d,proposalCondition==1 & copartisanCondition==1)$summaryDV)
doe_outpartisan <- t.test(subset(d,proposalCondition==1 & copartisanCondition==2)$summaryDV)
po_overall <- t.test(subset(d,proposalCondition==0)$summaryDV)
po_nonpartisan <- t.test(subset(d,proposalCondition==0 & copartisanCondition==0)$summaryDV)
po_copartisan <- t.test(subset(d,proposalCondition==0 & copartisanCondition==1)$summaryDV)
po_outpartisan <- t.test(subset(d,proposalCondition==0 & copartisanCondition==2)$summaryDV)

pdf("directEffectsQualtricsRP.pdf",width=12,height=16,paper='special') 
par(mar=c(5.1,6, 4.1, 2.1),mfrow=c(3,2))
plot(c(.9,1,1.1),c(court_nonpartisan$estimate,court_copartisan$estimate,court_outpartisan$estimate),ylab="Incumbent Support",col=c("#0072ce","#1e407c","darkgray"),
     main="Incumbent Support",cex.main=3,xaxt="n", xlab="", xlim=c(.75,3.25),
     cex.axis=2,cex.lab=2.5,ylim=c(.1,.7),pch=c(19,15,17),cex=2)
mtext(at=c(1,2,3),text=c("Supreme\nCourt","Department\nof Education","Post\nOffice"),side=1,line=3,cex=1.4)
points(x=c(1.9,2,2.1),y=c(doe_nonpartisan$estimate,doe_copartisan$estimate,doe_outpartisan$estimate),pch=c(19,15,17),col=c("#0072ce","#1e407c","darkgray"),cex=2)
segments(x0=.9,x1=.9,y0=court_nonpartisan$conf.int[1],y1=court_nonpartisan$conf.int[2],lwd=3, col="#0072ce")
segments(x0=1,x1=1,y0=court_copartisan$conf.int[1],y1=court_copartisan$conf.int[2],lwd=3, col="#1e407c")
segments(x0=1.1,x1=1.1,y0=court_outpartisan$conf.int[1],y1=court_outpartisan$conf.int[2],lwd=3, col="darkgray")
segments(x0=1.9,x1=1.9,y0=doe_nonpartisan$conf.int[1],y1=doe_nonpartisan$conf.int[2],lwd=3, col="#0072ce")
segments(x0=2,x1=2,y0=doe_copartisan$conf.int[1],y1=doe_copartisan$conf.int[2],lwd=3, col="#1e407c")
segments(x0=2.1,x1=2.1,y0=doe_outpartisan$conf.int[1],y1=doe_outpartisan$conf.int[2],lwd=3, col="darkgray")
points(x=c(2.9,3,3.1),y=c(po_nonpartisan$estimate,po_copartisan$estimate,po_outpartisan$estimate),pch=c(19,15,17),col=c("#0072ce","#1e407c","darkgray"),cex=2)
segments(x0=2.9,x1=2.9,y0=po_nonpartisan$conf.int[1],y1=po_nonpartisan$conf.int[2],lwd=3, col="#0072ce")
segments(x0=3,x1=3,y0=po_copartisan$conf.int[1],y1=po_copartisan$conf.int[2],lwd=3, col="#1e407c")
segments(x0=3.1,x1=3.1,y0=po_outpartisan$conf.int[1],y1=po_outpartisan$conf.int[2],lwd=3, col="darkgray")

legend("bottomright",pch=c(19,15,17),c("No Party","Copartisan","Outpartisan"),col=c("#0072ce","#1e407c","darkgray"),cex=1.5)

court_overall <- t.test(subset(d,proposalCondition==2)$voteDV)
court_nonpartisan <- t.test(subset(d,proposalCondition==2 & copartisanCondition==0)$voteDV)
court_copartisan <- t.test(subset(d,proposalCondition==2 & copartisanCondition==1)$voteDV)
court_outpartisan <- t.test(subset(d,proposalCondition==2 & copartisanCondition==2)$voteDV)
doe_overall <- t.test(subset(d,proposalCondition==1)$voteDV)
doe_nonpartisan <- t.test(subset(d,proposalCondition==1 & copartisanCondition==0)$voteDV)
doe_copartisan <- t.test(subset(d,proposalCondition==1 & copartisanCondition==1)$voteDV)
doe_outpartisan <- t.test(subset(d,proposalCondition==1 & copartisanCondition==2)$voteDV)
po_overall <- t.test(subset(d,proposalCondition==0)$voteDV)
po_nonpartisan <- t.test(subset(d,proposalCondition==0 & copartisanCondition==0)$voteDV)
po_copartisan <- t.test(subset(d,proposalCondition==0 & copartisanCondition==1)$voteDV)
po_outpartisan <- t.test(subset(d,proposalCondition==0 & copartisanCondition==2)$voteDV)

plot(c(.9,1,1.1),c(court_nonpartisan$estimate,court_copartisan$estimate,court_outpartisan$estimate),ylab="Vote Intention",col=c("#0072ce","#1e407c","darkgray"),
     main="Vote Intention",cex.main=3,xaxt="n", xlab="", xlim=c(.75,3.25),
     cex.axis=2,cex.lab=2.5,ylim=c(.1,.7),pch=c(19,15,17),cex=2)
mtext(at=c(1,2,3),text=c("Supreme\nCourt","Department\nof Education","Post\nOffice"),side=1,line=3,cex=1.4)
points(x=c(1.9,2,2.1),y=c(doe_nonpartisan$estimate,doe_copartisan$estimate,doe_outpartisan$estimate),pch=c(19,15,17),col=c("#0072ce","#1e407c","darkgray"),cex=2)
segments(x0=.9,x1=.9,y0=court_nonpartisan$conf.int[1],y1=court_nonpartisan$conf.int[2],lwd=3, col="#0072ce")
segments(x0=1,x1=1,y0=court_copartisan$conf.int[1],y1=court_copartisan$conf.int[2],lwd=3, col="#1e407c")
segments(x0=1.1,x1=1.1,y0=court_outpartisan$conf.int[1],y1=court_outpartisan$conf.int[2],lwd=3, col="darkgray")
segments(x0=1.9,x1=1.9,y0=doe_nonpartisan$conf.int[1],y1=doe_nonpartisan$conf.int[2],lwd=3, col="#0072ce")
segments(x0=2,x1=2,y0=doe_copartisan$conf.int[1],y1=doe_copartisan$conf.int[2],lwd=3, col="#1e407c")
segments(x0=2.1,x1=2.1,y0=doe_outpartisan$conf.int[1],y1=doe_outpartisan$conf.int[2],lwd=3, col="darkgray")
points(x=c(2.9,3,3.1),y=c(po_nonpartisan$estimate,po_copartisan$estimate,po_outpartisan$estimate),pch=c(19,15,17),col=c("#0072ce","#1e407c","darkgray"),cex=2)
segments(x0=2.9,x1=2.9,y0=po_nonpartisan$conf.int[1],y1=po_nonpartisan$conf.int[2],lwd=3, col="#0072ce")
segments(x0=3,x1=3,y0=po_copartisan$conf.int[1],y1=po_copartisan$conf.int[2],lwd=3, col="#1e407c")
segments(x0=3.1,x1=3.1,y0=po_outpartisan$conf.int[1],y1=po_outpartisan$conf.int[2],lwd=3, col="darkgray")

court_overall <- t.test(subset(d,proposalCondition==2)$proposalDV)
court_nonpartisan <- t.test(subset(d,proposalCondition==2 & copartisanCondition==0)$proposalDV)
court_copartisan <- t.test(subset(d,proposalCondition==2 & copartisanCondition==1)$proposalDV)
court_outpartisan <- t.test(subset(d,proposalCondition==2 & copartisanCondition==2)$proposalDV)
doe_overall <- t.test(subset(d,proposalCondition==1)$proposalDV)
doe_nonpartisan <- t.test(subset(d,proposalCondition==1 & copartisanCondition==0)$proposalDV)
doe_copartisan <- t.test(subset(d,proposalCondition==1 & copartisanCondition==1)$proposalDV)
doe_outpartisan <- t.test(subset(d,proposalCondition==1 & copartisanCondition==2)$proposalDV)
po_overall <- t.test(subset(d,proposalCondition==0)$proposalDV)
po_nonpartisan <- t.test(subset(d,proposalCondition==0 & copartisanCondition==0)$proposalDV)
po_copartisan <- t.test(subset(d,proposalCondition==0 & copartisanCondition==1)$proposalDV)
po_outpartisan <- t.test(subset(d,proposalCondition==0 & copartisanCondition==2)$proposalDV)

plot(c(.9,1,1.1),c(court_nonpartisan$estimate,court_copartisan$estimate,court_outpartisan$estimate),ylab="Proposal Approval",col=c("#0072ce","#1e407c","darkgray"),
     main="Proposal Approval",cex.main=3,xaxt="n", xlab="", xlim=c(.75,3.25),
     cex.axis=2,cex.lab=2.5,ylim=c(.1,.7),pch=c(19,15,17),cex=2)
mtext(at=c(1,2,3),text=c("Supreme\nCourt","Department\nof Education","Post\nOffice"),side=1,line=3,cex=1.4)
points(x=c(1.9,2,2.1),y=c(doe_nonpartisan$estimate,doe_copartisan$estimate,doe_outpartisan$estimate),pch=c(19,15,17),col=c("#0072ce","#1e407c","darkgray"),cex=2)
segments(x0=.9,x1=.9,y0=court_nonpartisan$conf.int[1],y1=court_nonpartisan$conf.int[2],lwd=3, col="#0072ce")
segments(x0=1,x1=1,y0=court_copartisan$conf.int[1],y1=court_copartisan$conf.int[2],lwd=3, col="#1e407c")
segments(x0=1.1,x1=1.1,y0=court_outpartisan$conf.int[1],y1=court_outpartisan$conf.int[2],lwd=3, col="darkgray")
segments(x0=1.9,x1=1.9,y0=doe_nonpartisan$conf.int[1],y1=doe_nonpartisan$conf.int[2],lwd=3, col="#0072ce")
segments(x0=2,x1=2,y0=doe_copartisan$conf.int[1],y1=doe_copartisan$conf.int[2],lwd=3, col="#1e407c")
segments(x0=2.1,x1=2.1,y0=doe_outpartisan$conf.int[1],y1=doe_outpartisan$conf.int[2],lwd=3, col="darkgray")
points(x=c(2.9,3,3.1),y=c(po_nonpartisan$estimate,po_copartisan$estimate,po_outpartisan$estimate),pch=c(19,15,17),col=c("#0072ce","#1e407c","darkgray"),cex=2)
segments(x0=2.9,x1=2.9,y0=po_nonpartisan$conf.int[1],y1=po_nonpartisan$conf.int[2],lwd=3, col="#0072ce")
segments(x0=3,x1=3,y0=po_copartisan$conf.int[1],y1=po_copartisan$conf.int[2],lwd=3, col="#1e407c")
segments(x0=3.1,x1=3.1,y0=po_outpartisan$conf.int[1],y1=po_outpartisan$conf.int[2],lwd=3, col="darkgray")

court_overall <- t.test(subset(d,proposalCondition==2)$jobpDV)
court_nonpartisan <- t.test(subset(d,proposalCondition==2 & copartisanCondition==0)$jobpDV)
court_copartisan <- t.test(subset(d,proposalCondition==2 & copartisanCondition==1)$jobpDV)
court_outpartisan <- t.test(subset(d,proposalCondition==2 & copartisanCondition==2)$jobpDV)
doe_overall <- t.test(subset(d,proposalCondition==1)$jobpDV)
doe_nonpartisan <- t.test(subset(d,proposalCondition==1 & copartisanCondition==0)$jobpDV)
doe_copartisan <- t.test(subset(d,proposalCondition==1 & copartisanCondition==1)$jobpDV)
doe_outpartisan <- t.test(subset(d,proposalCondition==1 & copartisanCondition==2)$jobpDV)
po_overall <- t.test(subset(d,proposalCondition==0)$jobpDV)
po_nonpartisan <- t.test(subset(d,proposalCondition==0 & copartisanCondition==0)$jobpDV)
po_copartisan <- t.test(subset(d,proposalCondition==0 & copartisanCondition==1)$jobpDV)
po_outpartisan <- t.test(subset(d,proposalCondition==0 & copartisanCondition==2)$jobpDV)

plot(c(.9,1,1.1),c(court_nonpartisan$estimate,court_copartisan$estimate,court_outpartisan$estimate),ylab="Job Performance",col=c("#0072ce","#1e407c","darkgray"),
     main="Job Performance",cex.main=3,xaxt="n", xlab="", xlim=c(.75,3.25),
     cex.axis=2,cex.lab=2.5,ylim=c(.1,.7),pch=c(19,15,17),cex=2)
mtext(at=c(1,2,3),text=c("Supreme\nCourt","Department\nof Education","Post\nOffice"),side=1,line=3,cex=1.4)
points(x=c(1.9,2,2.1),y=c(doe_nonpartisan$estimate,doe_copartisan$estimate,doe_outpartisan$estimate),pch=c(19,15,17),col=c("#0072ce","#1e407c","darkgray"),cex=2)
segments(x0=.9,x1=.9,y0=court_nonpartisan$conf.int[1],y1=court_nonpartisan$conf.int[2],lwd=3, col="#0072ce")
segments(x0=1,x1=1,y0=court_copartisan$conf.int[1],y1=court_copartisan$conf.int[2],lwd=3, col="#1e407c")
segments(x0=1.1,x1=1.1,y0=court_outpartisan$conf.int[1],y1=court_outpartisan$conf.int[2],lwd=3, col="darkgray")
segments(x0=1.9,x1=1.9,y0=doe_nonpartisan$conf.int[1],y1=doe_nonpartisan$conf.int[2],lwd=3, col="#0072ce")
segments(x0=2,x1=2,y0=doe_copartisan$conf.int[1],y1=doe_copartisan$conf.int[2],lwd=3, col="#1e407c")
segments(x0=2.1,x1=2.1,y0=doe_outpartisan$conf.int[1],y1=doe_outpartisan$conf.int[2],lwd=3, col="darkgray")
points(x=c(2.9,3,3.1),y=c(po_nonpartisan$estimate,po_copartisan$estimate,po_outpartisan$estimate),pch=c(19,15,17),col=c("#0072ce","#1e407c","darkgray"),cex=2)
segments(x0=2.9,x1=2.9,y0=po_nonpartisan$conf.int[1],y1=po_nonpartisan$conf.int[2],lwd=3, col="#0072ce")
segments(x0=3,x1=3,y0=po_copartisan$conf.int[1],y1=po_copartisan$conf.int[2],lwd=3, col="#1e407c")
segments(x0=3.1,x1=3.1,y0=po_outpartisan$conf.int[1],y1=po_outpartisan$conf.int[2],lwd=3, col="darkgray")

court_overall <- t.test(subset(d,proposalCondition==2)$mobilDV)
court_nonpartisan <- t.test(subset(d,proposalCondition==2 & copartisanCondition==0)$mobilDV)
court_copartisan <- t.test(subset(d,proposalCondition==2 & copartisanCondition==1)$mobilDV)
court_outpartisan <- t.test(subset(d,proposalCondition==2 & copartisanCondition==2)$mobilDV)
doe_overall <- t.test(subset(d,proposalCondition==1)$mobilDV)
doe_nonpartisan <- t.test(subset(d,proposalCondition==1 & copartisanCondition==0)$mobilDV)
doe_copartisan <- t.test(subset(d,proposalCondition==1 & copartisanCondition==1)$mobilDV)
doe_outpartisan <- t.test(subset(d,proposalCondition==1 & copartisanCondition==2)$mobilDV)
po_overall <- t.test(subset(d,proposalCondition==0)$mobilDV)
po_nonpartisan <- t.test(subset(d,proposalCondition==0 & copartisanCondition==0)$mobilDV)
po_copartisan <- t.test(subset(d,proposalCondition==0 & copartisanCondition==1)$mobilDV)
po_outpartisan <- t.test(subset(d,proposalCondition==0 & copartisanCondition==2)$mobilDV)

plot(c(.9,1,1.1),c(court_nonpartisan$estimate,court_copartisan$estimate,court_outpartisan$estimate),ylab="Mobilization",col=c("#0072ce","#1e407c","darkgray"),
     main="Mobilization",cex.main=3,xaxt="n", xlab="", xlim=c(.75,3.25),
     cex.axis=2,cex.lab=2.5,ylim=c(.1,.7),pch=c(19,15,17),cex=2)
mtext(at=c(1,2,3),text=c("Supreme\nCourt","Department\nof Education","Post\nOffice"),side=1,line=3,cex=1.4)
points(x=c(1.9,2,2.1),y=c(doe_nonpartisan$estimate,doe_copartisan$estimate,doe_outpartisan$estimate),pch=c(19,15,17),col=c("#0072ce","#1e407c","darkgray"),cex=2)
segments(x0=.9,x1=.9,y0=court_nonpartisan$conf.int[1],y1=court_nonpartisan$conf.int[2],lwd=3, col="#0072ce")
segments(x0=1,x1=1,y0=court_copartisan$conf.int[1],y1=court_copartisan$conf.int[2],lwd=3, col="#1e407c")
segments(x0=1.1,x1=1.1,y0=court_outpartisan$conf.int[1],y1=court_outpartisan$conf.int[2],lwd=3, col="darkgray")
segments(x0=1.9,x1=1.9,y0=doe_nonpartisan$conf.int[1],y1=doe_nonpartisan$conf.int[2],lwd=3, col="#0072ce")
segments(x0=2,x1=2,y0=doe_copartisan$conf.int[1],y1=doe_copartisan$conf.int[2],lwd=3, col="#1e407c")
segments(x0=2.1,x1=2.1,y0=doe_outpartisan$conf.int[1],y1=doe_outpartisan$conf.int[2],lwd=3, col="darkgray")
points(x=c(2.9,3,3.1),y=c(po_nonpartisan$estimate,po_copartisan$estimate,po_outpartisan$estimate),pch=c(19,15,17),col=c("#0072ce","#1e407c","darkgray"),cex=2)
segments(x0=2.9,x1=2.9,y0=po_nonpartisan$conf.int[1],y1=po_nonpartisan$conf.int[2],lwd=3, col="#0072ce")
segments(x0=3,x1=3,y0=po_copartisan$conf.int[1],y1=po_copartisan$conf.int[2],lwd=3, col="#1e407c")
segments(x0=3.1,x1=3.1,y0=po_outpartisan$conf.int[1],y1=po_outpartisan$conf.int[2],lwd=3, col="darkgray")
dev.off()

#######################
##Figure A3: Democrats
#######################
court_overall <- t.test(subset(dems,proposalCondition==2)$summaryDV)
court_nonpartisan <- t.test(subset(dems,proposalCondition==2 & copartisanCondition==0)$summaryDV)
court_copartisan <- t.test(subset(dems,proposalCondition==2 & copartisanCondition==1)$summaryDV)
court_outpartisan <- t.test(subset(dems,proposalCondition==2 & copartisanCondition==2)$summaryDV)
doe_overall <- t.test(subset(dems,proposalCondition==1)$summaryDV)
doe_nonpartisan <- t.test(subset(dems,proposalCondition==1 & copartisanCondition==0)$summaryDV)
doe_copartisan <- t.test(subset(dems,proposalCondition==1 & copartisanCondition==1)$summaryDV)
doe_outpartisan <- t.test(subset(dems,proposalCondition==1 & copartisanCondition==2)$summaryDV)
po_overall <- t.test(subset(dems,proposalCondition==0)$summaryDV)
po_nonpartisan <- t.test(subset(dems,proposalCondition==0 & copartisanCondition==0)$summaryDV)
po_copartisan <- t.test(subset(dems,proposalCondition==0 & copartisanCondition==1)$summaryDV)
po_outpartisan <- t.test(subset(dems,proposalCondition==0 & copartisanCondition==2)$summaryDV)
diff_overall <- t.test(subset(dems,proposalCondition==2)$summaryDV,subset(dems,proposalCondition==1)$summaryDV)
diff_nonpartisan <- t.test(subset(dems,proposalCondition==2 & copartisanCondition==0)$summaryDV,subset(dems,proposalCondition==1 & copartisanCondition==0)$summaryDV)
diff_copartisan <- t.test(subset(dems,proposalCondition==2 & copartisanCondition==1)$summaryDV,subset(dems,proposalCondition==1 & copartisanCondition==1)$summaryDV)
diff_outpartisan <- t.test(subset(dems,proposalCondition==2 & copartisanCondition==2)$summaryDV,subset(dems,proposalCondition==1 & copartisanCondition==2)$summaryDV)

ctpo_diff_overall <- t.test(subset(dems,proposalCondition==2)$summaryDV,subset(dems,proposalCondition==0)$summaryDV)
ctpo_diff_nonpartisan <- t.test(subset(dems,proposalCondition==2 & copartisanCondition==0)$summaryDV,subset(dems,proposalCondition==0 & copartisanCondition==0)$summaryDV)
ctpo_diff_copartisan <- t.test(subset(dems,proposalCondition==2 & copartisanCondition==1)$summaryDV,subset(dems,proposalCondition==0 & copartisanCondition==1)$summaryDV)
ctpo_diff_outpartisan <- t.test(subset(dems,proposalCondition==2 & copartisanCondition==2)$summaryDV,subset(dems,proposalCondition==0 & copartisanCondition==2)$summaryDV)

doepo_diff_overall <- t.test(subset(dems,proposalCondition==1)$summaryDV,subset(dems,proposalCondition==0)$summaryDV)
doepo_diff_nonpartisan <- t.test(subset(dems,proposalCondition==1 & copartisanCondition==0)$summaryDV,subset(dems,proposalCondition==0 & copartisanCondition==0)$summaryDV)
doepo_diff_copartisan <- t.test(subset(dems,proposalCondition==1 & copartisanCondition==1)$summaryDV,subset(dems,proposalCondition==0 & copartisanCondition==1)$summaryDV)
doepo_diff_outpartisan <- t.test(subset(dems,proposalCondition==1 & copartisanCondition==2)$summaryDV,subset(dems,proposalCondition==0 & copartisanCondition==2)$summaryDV)

pdf("summaryQualtricsMainRPDems.pdf",width=15,height=5,paper='special') 
par(mar=c(5.1,6, 4.1, 2.1),mfrow=c(1,3))
plot(c(3,2,1),c(po_overall$estimate,doe_overall$estimate,court_overall$estimate),ylab="Incumbent Support",
     main="Direct Effects",cex.main=2,xaxt="n", xlab="", xlim=c(.75,3.25),
     cex.axis=1.5,cex.lab=1.5,ylim=c(.2,.8),pch=19,cex=2)
mtext(at=c(1,2,3),text=c("Supreme\nCourt","Department\nof Education","Post\nOffice"),side=1,line=3,cex=1)
segments(x0=3,x1=3,y0=po_overall$conf.int[1],y1=po_overall$conf.int[2],lwd=3, col="black")
segments(x0=2,x1=2,y0=doe_overall$conf.int[1],y1=doe_overall$conf.int[2],lwd=3, col="black")
segments(x0=1,x1=1,y0=court_overall$conf.int[1],y1=court_overall$conf.int[2],lwd=3, col="black")

plot(c(.9,1,1.1),c(court_nonpartisan$estimate,court_copartisan$estimate,court_outpartisan$estimate),ylab="Incumbent Support",col=c("#0072ce","#1e407c","darkgray"),
     main="Direct Effects",cex.main=2,xaxt="n", xlab="", xlim=c(.75,3.25),
     cex.axis=1.5,cex.lab=1.5,ylim=c(.2,.8),pch=c(19,15,17),cex=2)
mtext(at=c(1,2,3),text=c("Supreme\nCourt","Department\nof Education","Post\nOffice"),side=1,line=3,cex=1)
points(x=c(1.9,2,2.1),y=c(doe_nonpartisan$estimate,doe_copartisan$estimate,doe_outpartisan$estimate),pch=c(19,15,17),col=c("#0072ce","#1e407c","darkgray"),cex=2)
segments(x0=.9,x1=.9,y0=court_nonpartisan$conf.int[1],y1=court_nonpartisan$conf.int[2],lwd=3, col="#0072ce")
segments(x0=1,x1=1,y0=court_copartisan$conf.int[1],y1=court_copartisan$conf.int[2],lwd=3, col="#1e407c")
segments(x0=1.1,x1=1.1,y0=court_outpartisan$conf.int[1],y1=court_outpartisan$conf.int[2],lwd=3, col="darkgray")
segments(x0=1.9,x1=1.9,y0=doe_nonpartisan$conf.int[1],y1=doe_nonpartisan$conf.int[2],lwd=3, col="#0072ce")
segments(x0=2,x1=2,y0=doe_copartisan$conf.int[1],y1=doe_copartisan$conf.int[2],lwd=3, col="#1e407c")
segments(x0=2.1,x1=2.1,y0=doe_outpartisan$conf.int[1],y1=doe_outpartisan$conf.int[2],lwd=3, col="darkgray")
points(x=c(2.9,3,3.1),y=c(po_nonpartisan$estimate,po_copartisan$estimate,po_outpartisan$estimate),pch=c(19,15,17),col=c("#0072ce","#1e407c","darkgray"),cex=2)
segments(x0=2.9,x1=2.9,y0=po_nonpartisan$conf.int[1],y1=po_nonpartisan$conf.int[2],lwd=3, col="#0072ce")
segments(x0=3,x1=3,y0=po_copartisan$conf.int[1],y1=po_copartisan$conf.int[2],lwd=3, col="#1e407c")
segments(x0=3.1,x1=3.1,y0=po_outpartisan$conf.int[1],y1=po_outpartisan$conf.int[2],lwd=3, col="darkgray")

legend("bottomright",pch=c(19,15,17),c("No Party","Copartisan","Outpartisan"),col=c("#0072ce","#1e407c","darkgray"),cex=1.5)

plot(c(1,2,3,4),c(diff_overall$estimate[1]-diff_overall$estimate[2],
                  diff_nonpartisan$estimate[1]-diff_nonpartisan$estimate[2],
                  diff_copartisan$estimate[1]-diff_copartisan$estimate[2],
                  diff_outpartisan$estimate[1]-diff_outpartisan$estimate[2]),ylab="mean(Court) - mean(Dept. of Ed.)", 
     col=c("black","#0072ce","#1e407c","darkgray"),
     main="Mean Differences",cex.main=2,xaxt="n", xlab="", xlim=c(.75,4.25),
     cex.axis=1.5,cex.lab=1.5,ylim=c(-.3,.1),pch=c(18,19,15,17),bg="black",cex=c(2.5,2,2,2))
mtext(at=c(1,2,3,4),text=c("Overall","No Party","Copartisan","Outpartisan"),side=1,line=1.5,cex=1)
segments(x0=1,x1=1,y0=diff_overall$conf.int[1],y1=diff_overall$conf.int[2],lwd=3, col="black")
segments(x0=2,x1=2,y0=diff_nonpartisan$conf.int[1],y1=diff_nonpartisan$conf.int[2],lwd=3, col="#0072ce")
segments(x0=3,x1=3,y0=diff_copartisan$conf.int[1],y1=diff_copartisan$conf.int[2],lwd=3, col="#1e407c")
segments(x0=4,x1=4,y0=diff_outpartisan$conf.int[1],y1=diff_outpartisan$conf.int[2],lwd=3, col="darkgray")
abline(h=0,col="gray70",lwd=3,lty=2)
dev.off()

#######################
##Figure A3: Republicans
#######################
court_overall <- t.test(subset(reps,proposalCondition==2)$summaryDV)
court_nonpartisan <- t.test(subset(reps,proposalCondition==2 & copartisanCondition==0)$summaryDV)
court_copartisan <- t.test(subset(reps,proposalCondition==2 & copartisanCondition==1)$summaryDV)
court_outpartisan <- t.test(subset(reps,proposalCondition==2 & copartisanCondition==2)$summaryDV)
doe_overall <- t.test(subset(reps,proposalCondition==1)$summaryDV)
doe_nonpartisan <- t.test(subset(reps,proposalCondition==1 & copartisanCondition==0)$summaryDV)
doe_copartisan <- t.test(subset(reps,proposalCondition==1 & copartisanCondition==1)$summaryDV)
doe_outpartisan <- t.test(subset(reps,proposalCondition==1 & copartisanCondition==2)$summaryDV)
po_overall <- t.test(subset(reps,proposalCondition==0)$summaryDV)
po_nonpartisan <- t.test(subset(reps,proposalCondition==0 & copartisanCondition==0)$summaryDV)
po_copartisan <- t.test(subset(reps,proposalCondition==0 & copartisanCondition==1)$summaryDV)
po_outpartisan <- t.test(subset(reps,proposalCondition==0 & copartisanCondition==2)$summaryDV)
diff_overall <- t.test(subset(reps,proposalCondition==2)$summaryDV,subset(reps,proposalCondition==1)$summaryDV)
diff_nonpartisan <- t.test(subset(reps,proposalCondition==2 & copartisanCondition==0)$summaryDV,subset(reps,proposalCondition==1 & copartisanCondition==0)$summaryDV)
diff_copartisan <- t.test(subset(reps,proposalCondition==2 & copartisanCondition==1)$summaryDV,subset(reps,proposalCondition==1 & copartisanCondition==1)$summaryDV)
diff_outpartisan <- t.test(subset(reps,proposalCondition==2 & copartisanCondition==2)$summaryDV,subset(reps,proposalCondition==1 & copartisanCondition==2)$summaryDV)

ctpo_diff_overall <- t.test(subset(reps,proposalCondition==2)$summaryDV,subset(reps,proposalCondition==0)$summaryDV)
ctpo_diff_nonpartisan <- t.test(subset(reps,proposalCondition==2 & copartisanCondition==0)$summaryDV,subset(reps,proposalCondition==0 & copartisanCondition==0)$summaryDV)
ctpo_diff_copartisan <- t.test(subset(reps,proposalCondition==2 & copartisanCondition==1)$summaryDV,subset(reps,proposalCondition==0 & copartisanCondition==1)$summaryDV)
ctpo_diff_outpartisan <- t.test(subset(reps,proposalCondition==2 & copartisanCondition==2)$summaryDV,subset(reps,proposalCondition==0 & copartisanCondition==2)$summaryDV)

doepo_diff_overall <- t.test(subset(reps,proposalCondition==1)$summaryDV,subset(reps,proposalCondition==0)$summaryDV)
doepo_diff_nonpartisan <- t.test(subset(reps,proposalCondition==1 & copartisanCondition==0)$summaryDV,subset(reps,proposalCondition==0 & copartisanCondition==0)$summaryDV)
doepo_diff_copartisan <- t.test(subset(reps,proposalCondition==1 & copartisanCondition==1)$summaryDV,subset(reps,proposalCondition==0 & copartisanCondition==1)$summaryDV)
doepo_diff_outpartisan <- t.test(subset(reps,proposalCondition==1 & copartisanCondition==2)$summaryDV,subset(reps,proposalCondition==0 & copartisanCondition==2)$summaryDV)

pdf("summaryQualtricsMainRPReps.pdf",width=15,height=5,paper='special') 
par(mar=c(5.1,6, 4.1, 2.1),mfrow=c(1,3))
plot(c(3,2,1),c(po_overall$estimate,doe_overall$estimate,court_overall$estimate),ylab="Incumbent Support",
     main="Direct Effects",cex.main=2,xaxt="n", xlab="", xlim=c(.75,3.25),
     cex.axis=1.5,cex.lab=1.5,ylim=c(.2,.8),pch=19,cex=2)
mtext(at=c(1,2,3),text=c("Supreme\nCourt","Department\nof Education","Post\nOffice"),side=1,line=3,cex=1)
segments(x0=3,x1=3,y0=po_overall$conf.int[1],y1=po_overall$conf.int[2],lwd=3, col="black")
segments(x0=2,x1=2,y0=doe_overall$conf.int[1],y1=doe_overall$conf.int[2],lwd=3, col="black")
segments(x0=1,x1=1,y0=court_overall$conf.int[1],y1=court_overall$conf.int[2],lwd=3, col="black")

plot(c(.9,1,1.1),c(court_nonpartisan$estimate,court_copartisan$estimate,court_outpartisan$estimate),ylab="Incumbent Support",col=c("#0072ce","#1e407c","darkgray"),
     main="Direct Effects",cex.main=2,xaxt="n", xlab="", xlim=c(.75,3.25),
     cex.axis=1.5,cex.lab=1.5,ylim=c(.2,.8),pch=c(19,15,17),cex=2)
mtext(at=c(1,2,3),text=c("Supreme\nCourt","Department\nof Education","Post\nOffice"),side=1,line=3,cex=1)
points(x=c(1.9,2,2.1),y=c(doe_nonpartisan$estimate,doe_copartisan$estimate,doe_outpartisan$estimate),pch=c(19,15,17),col=c("#0072ce","#1e407c","darkgray"),cex=2)
segments(x0=.9,x1=.9,y0=court_nonpartisan$conf.int[1],y1=court_nonpartisan$conf.int[2],lwd=3, col="#0072ce")
segments(x0=1,x1=1,y0=court_copartisan$conf.int[1],y1=court_copartisan$conf.int[2],lwd=3, col="#1e407c")
segments(x0=1.1,x1=1.1,y0=court_outpartisan$conf.int[1],y1=court_outpartisan$conf.int[2],lwd=3, col="darkgray")
segments(x0=1.9,x1=1.9,y0=doe_nonpartisan$conf.int[1],y1=doe_nonpartisan$conf.int[2],lwd=3, col="#0072ce")
segments(x0=2,x1=2,y0=doe_copartisan$conf.int[1],y1=doe_copartisan$conf.int[2],lwd=3, col="#1e407c")
segments(x0=2.1,x1=2.1,y0=doe_outpartisan$conf.int[1],y1=doe_outpartisan$conf.int[2],lwd=3, col="darkgray")
points(x=c(2.9,3,3.1),y=c(po_nonpartisan$estimate,po_copartisan$estimate,po_outpartisan$estimate),pch=c(19,15,17),col=c("#0072ce","#1e407c","darkgray"),cex=2)
segments(x0=2.9,x1=2.9,y0=po_nonpartisan$conf.int[1],y1=po_nonpartisan$conf.int[2],lwd=3, col="#0072ce")
segments(x0=3,x1=3,y0=po_copartisan$conf.int[1],y1=po_copartisan$conf.int[2],lwd=3, col="#1e407c")
segments(x0=3.1,x1=3.1,y0=po_outpartisan$conf.int[1],y1=po_outpartisan$conf.int[2],lwd=3, col="darkgray")

legend("bottomright",pch=c(19,15,17),c("No Party","Copartisan","Outpartisan"),col=c("#0072ce","#1e407c","darkgray"),cex=1.5)

plot(c(1,2,3,4),c(diff_overall$estimate[1]-diff_overall$estimate[2],
                  diff_nonpartisan$estimate[1]-diff_nonpartisan$estimate[2],
                  diff_copartisan$estimate[1]-diff_copartisan$estimate[2],
                  diff_outpartisan$estimate[1]-diff_outpartisan$estimate[2]),ylab="mean(Court) - mean(Dept. of Ed.)", 
     col=c("black","#0072ce","#1e407c","darkgray"),
     main="Mean Differences",cex.main=2,xaxt="n", xlab="", xlim=c(.75,4.25),
     cex.axis=1.5,cex.lab=1.5,ylim=c(-.3,.1),pch=c(18,19,15,17),bg="black",cex=c(2.5,2,2,2))
mtext(at=c(1,2,3,4),text=c("Overall","No Party","Copartisan","Outpartisan"),side=1,line=1.5,cex=1)
segments(x0=1,x1=1,y0=diff_overall$conf.int[1],y1=diff_overall$conf.int[2],lwd=3, col="black")
segments(x0=2,x1=2,y0=diff_nonpartisan$conf.int[1],y1=diff_nonpartisan$conf.int[2],lwd=3, col="#0072ce")
segments(x0=3,x1=3,y0=diff_copartisan$conf.int[1],y1=diff_copartisan$conf.int[2],lwd=3, col="#1e407c")
segments(x0=4,x1=4,y0=diff_outpartisan$conf.int[1],y1=diff_outpartisan$conf.int[2],lwd=3, col="darkgray")
abline(h=0,col="gray70",lwd=3,lty=2)
dev.off()